package com.tanhua.dubbo.api.mongo;

import com.tanhua.domain.mongo.Exam;
import com.tanhua.domain.mongo.Level;
import com.tanhua.domain.mongo.Options;
import com.tanhua.domain.mongo.Questions;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: Alfred
 * @Date: 2021/04/20/17:48
 * @Description:
 */
@Service
public class SoulApiImpl implements SoulApi{

    @Autowired
    private MongoTemplate mongoTemplate;

    /**
     * @Description: 获取所有问卷的集合
     * @Param: []
     * @return: java.util.List<com.tanhua.domain.mongo.Exam>
     * @Author: Alfred
     * @Date: 2021/4/20
     */
    @Override
    public List<Exam> getList() {
        List<Exam> list = mongoTemplate.findAll(Exam.class);
        return list;
    }

    /**
    * @Description: 根据问卷id获取对应试题的集合
    * @Param: [examId]
    * @return: java.util.List<com.tanhua.domain.mongo.Questions>
    * @Author: Alfred
    * @Date: 2021/4/20
    */
    @Override
    public List<Questions> getQuestionList(String examId) {
        Query query = new Query();
        query.addCriteria(Criteria.where("exam_id").is(examId));
        query.limit(10);

        List<Questions> questions = mongoTemplate.find(query, Questions.class);
        return questions;
    }

    /**
    * @Description: 根据登录用户id获取对应的测灵魂题目等级
    * @Param: [userLoginId]
    * @return: com.tanhua.domain.mongo.Level
    * @Author: Alfred
    * @Date: 2021/4/20
    */
    @Override
    public Level getUserLevel(Long userLoginId) {
        Query query = new Query();
        query.addCriteria(Criteria.where("user_Id").is(userLoginId.toString()));
        Level level = mongoTemplate.findOne(query, Level.class);
        return level;
    }

    /**
    * @Description: 根据examId获取报告id
    * @Param: [examId]
    * @return: java.lang.String
    * @Author: Alfred
    * @Date: 2021/4/20
    */
    @Override
    public String getReportId(String examId) {
//        Query query = new Query();
//        query.addCriteria(Criteria.where("user_Id").is(userLoginId));
        return null;
    }

    @Override
    public List<Options> getOptionList(String question_id) {
        Query query = new Query();
        query.addCriteria(Criteria.where("question_Id").is(question_id));
        List<Options> options = mongoTemplate.find(query, Options.class);
        return options;
    }

}
